import { PeaceColumn } from '@/components/type/PeaceColumn'
import { NullUtil } from '@/util/NullUtil'
import PeaceOption from '@/components/type/PeaceOption'
import { ObjectUtil } from '@/util/ObjectUtil'

export const initColumnPeaceOption = (option:PeaceOption) => {
  if (ObjectUtil.isEmpty(option)){
    return option
  }
  if (ObjectUtil.isNotNullAndUndefined(option.peaceOption)){
    return option
  }
  if (option.enum && option.enumLabel){
    option.peaceOption =  Object.keys(option!.enum ? option!.enum : []).map((key) => ({
      label: option.enumLabel ? (option.enumLabel as Record<string, string>)[key] : 'undefined_label',
      value: key,
    }))
    return option
  }
  if(ObjectUtil.isNotNullAndUndefined(option.peaceApi)){
    option.peaceApi(option.peaceApiParam).then(res=>{
      option.peaceOption = res ?? [] as unknown[]
    })
    return option
  }
  return option
}
